
ifeq ("$(shell whoami)", "malloy")
  CXX = clang++
else
  CXX = g++
endif

# Warnings frequently signal eventual errors:
CXXFLAGS=`sdl-config --cflags` -g -W -Wall -Weffc++ -Wextra -pedantic -O0

ifeq ("$(shell uname)", "Darwin")
  LDFLAGS =
else
  ifeq ("$(shell uname)", "Linux")
  LDFLAGS = `sdl-config --libs` -lSDL_ttf -lSDL_image -lexpat -lSDL_draw
  endif
endif

OBJS = \
	main.o \
	controller.o \
	gamedata.o \
	parseXML.o \
	model.o \
	clock.o \
	vector2f.o \
	sprite.o \
	frame.o \
	viewport.o \
	world.o \
	lsystem.o \
	ioManager.o\
	frameFactory.o\
	spriteFactory.o\
	grammarHandler.o

EXEC = run

# $< refers to the first dependency
%.o: %.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@

# $@ refers to the target
$(EXEC): $(OBJS)
	$(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LDFLAGS)

main.o: main.cpp
controller.o: controller.cpp controller.h model.h
parseXML.o: parseXML.cpp parseXML.h
gamedata.o: gamedata.cpp gamedata.h parseXML.h
model.o: controller.cpp model.h sprite.h viewport.h world.h clock.h
clock.o: clock.cpp clock.h
vector2f.o: vector2f.cpp vector2f.h
sprite.o: sprite.cpp sprite.h drawable.h frame.h
frame.o: frame.cpp frame.h ioManager.h
viewport.o: viewport.cpp viewport.h sprite.h
world.o: world.cpp world.h frame.h viewport.h
lsystem.o: lsystem.cpp lsystem.h sprite.h
ioManager.o: ioManager.cpp ioManager.h
frameFactory.o:frameFactory.cpp frameFactory.h frame.h
spriteFactory.o:spriteFactory.cpp spriteFactory.h sprite.h
grammarHandler.o:grammarHandler.cpp grammarHandler.h handler.h

clean:
	rm -rf $(OBJS)
	rm -rf $(EXEC)
